<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>0</h1>
<h2>0</h2>
<!--script标签建议写在body标签的边上-->
<script>
  let count=0;
  //匿名方法开启定时器
  /*setInterval(function (){
    count++;
    let h1=document.querySelector("h1");
    h1.innerText=count;
  },1000);*/
  function f(){
    count+=2;
    let h1=document.querySelector("h1");
    h1.innerText=count;
    if (count==100){
      //停止定时器
      clearInterval(timer);
    }
  }
  //开启定时器  当方法作为参数进行传递时不写
  let timer = setInterval(f,200);

  //开启只执行一次的定时器
  setTimeout(function (){
    alert("时间到！")
  },3000)



</script>
</body>
</html>